<html>
<head>
	<meta charset='utf-8' />
	<title>后台管理</title>
	<meta http-equiv="keywords" content="求职,招聘,房屋,出租,出售,求租,求购,宠物,二手,二手车,二手物品,旧货,寻物,寻人,出兑,外兑"> 
	<meta http-equiv="description" content="便民信息网,房屋租售,宠物交易,二手物品,二手车辆,寻物寻人,出兑信息">  
	<meta name="description" content="便民信息网,房屋租售,宠物交易,二手物品,二手车辆,寻物寻人,出兑信息"/>
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
	<style>
		@media screen and (max-width:450px){
			#nav_bottom{width:98%;margin:0 auto}
			#content{width:98%;margin:0 auto}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
		@media screen and (min-width:450px){
			#nav_bottom{width:450px;margin:0 auto}
			#content{width:450px;margin:0 auto}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
		.info_item{color:#444;margin:15px 0;display:flex}
		.info_item > div:last-child{flex:1}
	</style>
</head>
<body style='padding:0;margin:0;background:#eee'>
<!-- 1 Content容器 -->
<div id='Content'>
	<!-- 3 内容区-->
	<div style='margin:10px 0;word-break:break-all;padding:10px;'>
		<div style='float:right;text-align:right' onclick='After_Admin_Exit()'>退出</div>

		<h2 style='text-align:center;'>后台管理-组权限管理</h2>
		<div>当前组：<span id='group_name'></span></div>
		<hr>
		
	

		<div id='a'></div>

		<!--修改密码浮动区-->
		<div id='admin_group_fun_list' style='padding:20px;'>
			<div>权限设置</div>
			<div id='funs_list'></div>
		</div>

		<div style='margin:20px;text-align:center'>
			<button onclick='Go_Back()'>返回</button>
		</div>

		<div style='height:100px'></div>			
	
	</div>	<!-- 3 内容区结束-->	

</div><!-- 1 Content容器结束 -->







<!--底部导航容器-->
<div id='Nav_Bottom' style='position:fixed;bottom:0;width:100%;height:45px'>



</body>
</html>


<script src='./Public/jquery.js'></script>
<script src='./Public/fun.js'></script>
<script>
	Check_After_User_Cookie();	//检测登陆状态

	var priv_name = 'after_set_group_set_fun';
	Priv_Check(priv_name,function(res){
		if(res != 'ok'){
			alert('没有权限!');
			//location.href = document.referrer;
			exit;
		}
	});






	//加载底部导航栏
	Load_NavBottom('after');

	$(function(){

		$('#group_name').text(GetUrlParm('gname'));

		Cat_Group_Grant(GetUrlParm('gid'));




	});




	//显示页面及功能列表
	function Cat_Group_Grant(gid,gname){
		var type = "After_Cat_Group_Grant";
		Token(type,function(t){
			$.ajax({
				url:url,
				type:'post',
				data:{
					token:t,
					type:type,
					gid:gid
				},
				success(res){
					var data = JSON.parse(res);
					//alert(data.privilege[0]);
					var list = [];
					for(var i=0;i<data.funs.length;i++){
						var obj = new Object();
						if(data.funs[i][3] == 0){	//如果是页面
							obj.page = data.funs[i];
							list.push(obj);
						}
					}

					//alert(list[0][]);
					for(var j=0;j<list.length;j++){
						var tmp_arr = [];
						for(var i=0;i<data.funs.length;i++){
						//alert(data.funs[i][3]);
							if(list[j].page[0] == data.funs[i][3]){
								tmp_arr.push(data.funs[i]);
							}
						}
						list[j].fun = tmp_arr;
					}
					//alert(list[0].fun[2][2]);
					var list_str = '';
					for(var i=0;i<list.length;i++){
						list_str += "<div>";

						var checked_stat = '';	//设置是否选择
						for(var l1=0;l1<data.privilege.length;l1++){
							if(data.privilege[l1] == list[i].page[1]){
								var checked_stat = 'checked';
							}
						}
						list_str += "页面："+list[i].page[2]+"<input type='checkbox' name='funs' value='"+list[i].page[1]+"' "+checked_stat+" />";
						for(var j=0;j<list[i].fun.length;j++){

							var checked_stat2 = '';	//设置是否选择
							for(var l1=0;l1<data.privilege.length;l1++){
								if(data.privilege[l1] == list[i].fun[j][1]){
									var checked_stat2 = 'checked';
								}
							}
							list_str += "<div style='text-indent:50px'>";
							list_str += "功能："+list[i].fun[j][2]+"<input type='checkbox' name='funs' value='"+list[i].fun[j][1]+"' "+checked_stat2+" />";
							list_str += "</div>";
						}
						list_str += "</div>";

					}
					list_str += "<div style='margin:20px;text-align:center'>";
					list_str += "<button onclick='Add_Fun_For_Group()'>提交</button>　";
					list_str += "</div>";
					$('#funs_list').html(list_str);
				}
			});
		});
	}


	//提交组权限
	function Add_Fun_For_Group(){
		var priv_name = 'AfterSetGroupSetFun_Submit';
		Priv_Check(priv_name,function(res){
			if(res != 'ok'){
				alert('没有权限!');
				//location.href = document.referrer;
				exit;
			}
		});
		var funs = [];
		$('input[name=funs]').each(function(i,o){
			if(o.checked){
				//alert($(o).val());
				funs.push($(o).val());
			}
		});
		if(funs.length < 1){
			funs = 'none';
		}
			var type = 'Add_Fun_For_Group';
			Token(type,function(t){
				$.ajax({
					url:url,
					type:'post',
					data:{
						token:t,
						type:type,
						ids:funs,
						gid:GetUrlParm('gid')
					},
					success(res){
						if(res == 'ok'){
							alert('操作成功!');
							location.href='after_set_group.html';
						}else{
							alert('操作失败!');
						}
					}
				});
			});
	}

	//返回分组页面
	function Go_Back(){
		location.href='after_set_group.html';
	}

</script>

